package com.xgpro.mapper.studycentre;

import com.xgpro.domain.studycentre.entity.Tea;
import com.xgpro.domain.studycentre.vo.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;


/**
 * @author tx
 * @version 1.0
 * @date 2019/10/11 22:10
 */
public interface TeaMapper extends Mapper<Tea> {

    /**
     * 查询内外部导师
     * @param teaFront
     * @return
     */
    @Select("<script>" +
            " select t_tea.user_id as id,t_user.username as username,t_deptment.name as deptName,t_user.photo as photo from t_tea left join  t_user on t_tea.user_id = t_user.id left join t_deptment on t_user.dept_id=t_deptment.id " +
            "<where>" +
            " t_tea.tea_type=#{teaFront.teaType}  " +
            " <if test=\"teaFront.name != null and teaFront.name!='' \"> " +
            "  and t_user.username like CONCAT('%',#{teaFront.name},'%')" +
            " </if>" +
            "</where>" +
            "</script>")
    List<TeaSimple> selectTeaSimple(@Param("teaFront") TeaFront teaFront);

    /**
     * 查询首页讲师风采
     * @return
     */
    @Select(" select t_tea.user_id as id,t_user.username as username,t_deptment.name as deptName,t_user.photo as photo from t_tea left join  t_user on t_tea.user_id = t_user.id left join t_deptment on t_user.dept_id=t_deptment.id where t_tea.is_good=1")
    List<TeaSimple> selectGoodTea();

    /**
     * 根据id查询内外部导师详情
     * @param id
     * @return
     */
    @Select("select t_user.id as id,t_user.photo as photo ,t_user.username as username,t_edu.edu_kind as eduKind, " +
            " t_edu.school as school,t_deptment.name as deptName,t_tea.honor_title as honorTitle,t_tea.job_title as  jobTitle, " +
            " t_tea.achievement as achievement,t_tea.tea_type as teaType,t_tea.is_good as isGood from t_user left join t_tea on t_user.id =t_tea.user_id left join t_edu on t_edu.id=t_user.edu_id " +
            " left join t_deptment on t_deptment.id=t_user.dept_id   where t_user.id=#{id}")
    TeaInfoBack selectTeaInfoById(Integer id);

    /**
     * 查询导师pc端列表
     * @param name
     * @param teaType
     * @return
     */
    @Select("<script>" +
            " select t_tea.id as id,t_tea.user_id as userId,t_user.username as username,t_tea.tea_type as teaType,t_deptment.name as deptName,t_tea.honor_title as honorTitle,t_edu.school as school from t_tea left join  t_user on t_tea.user_id = t_user.id left join t_deptment on t_user.dept_id=t_deptment.id left join t_edu on t_user.edu_id =t_edu.id " +
            "<where>" +
            " <if test=\"deptName != null and deptName!='' \"> " +
            "     t_deptment.name like CONCAT('%',#{deptName},'%')" +
            " </if>" +
            " <if test=\"teaType != null and teaType!='' or teaType==0 \"> " +
            "  and t_tea.tea_type=#{teaType}  " +
            " </if>" +
            " <if test=\"name != null and name!='' \"> " +
            "  and t_user.username like CONCAT('%',#{name},'%')" +
            " </if>" +
            " <if test=\"isGood != null \"> " +
            "  and t_tea.is_good =#{isGood}" +
            " </if>" +
            "</where>" +
            "</script>")
    List<TeaPCBack> selectTeaPCList(@Param("name") String name,@Param("teaType") Integer teaType,@Param("deptName") String deptName,@Param("isGood") Integer isGood);

    /**
     * 批量删除导师
     * @param ids
     * @return
     */
    @Delete("<script>" +
            " delete from t_tea where  id in " +
            " <foreach collection='list' index='index' item='id'  open='(' separator=',' close=')'> " +
            "  #{id}" +
            " </foreach>" +
            " </script>")
    Integer deleteTeaByIds(List<Integer> ids);

    /**
     * 外部导师搜索
     * @param teaName
     * @return
     */
    @Select("<script>" +
            " select t_user.id as userId,t_user.username as teaName from t_tea left join  t_user on t_tea.user_id = t_user.id left join t_deptment on t_user.dept_id=t_deptment.id left join t_edu on t_user.edu_id =t_edu.id " +
            "<where>" +
            "  t_tea.tea_type=1  " +
            " <if test=\"teaName != null and teaName!='' \"> " +
            "  and t_user.username like CONCAT('%',#{teaName},'%')" +
            " </if>" +
            "</where>" +
            "</script>")
    List<Map> qryTeaBySelect(@Param("teaName") String teaName);




}
